package com.wx.handler.security;

import com.wx.common.WrapMapper;
import com.wx.utils.ResponseUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


/**
 * <p>Title:      CustomerAuthenticationFailureHandler. </p>
 * <p>Description 认证失败处理器 </p>
 * <p>Copyright: Copyright (c) 2016</p>
 * <p>Company:    医百科技有限公司 </p>
 *
 * @author         <a href="xinglinglove1029@163.com"/>杨文生</a>
 * @since      2020/9/18 20:32
 */
@Slf4j
@Component("customerAuthenticationFailureHandler")
public class CustomerAuthenticationFailureHandler implements AuthenticationFailureHandler {

    @Override
    public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException {
        log.info("登录失败 原因: {}", exception.getMessage());
        ResponseUtil.write(response, WrapMapper.error(exception.getMessage()));

    }
}
